
package com.android.matmanual;

import android.app.Activity;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class FactoryTestResultListActivity extends Activity implements OnItemClickListener {
	WakeLock mWakeLock;
	
	ListView mListView;
	FactoryTestResultListAdapter mAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.result_layout);
		setContentView(R.layout.factory_test_result);
		setTitle("MAT");
		
	    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); 
	    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "XYTEST"); 
	    mWakeLock.acquire();
	    
//	    TextView show = (TextView)findViewById(R.id.textView);
//	    String result_str = new String();
//	    for (int i = 0; i < TestControl.name_list.length; i++) {
//	    	result_str += getResources().getString(TestControl.name_list[i]);
//	    	result_str += " ";
//	    	if (TestControl.result_list[i]) {
//	    		result_str += getResources().getString(R.string.success);
//	    	} else {
//	    		result_str += getResources().getString(R.string.fail);
//	    	}
//	    	result_str += "\r\n";
//	    }
//	    show.setText(result_str);
	    
	    mListView = (ListView) findViewById(R.id.factory_test_result_list);
	    String[] mName  = new String[TestControl.name_list.length+1];
	    String[] mResult  = new String[TestControl.name_list.length];	
	    for (int i = 0; i < TestControl.name_list.length; i++) {
	    	mName[i] = getResources().getString(TestControl.name_list[i]);

	    	if (TestControl.result_list[i]) {
	    		mResult[i] = getResources().getString(R.string.success);
	    	} else {
	    		mResult[i] = getResources().getString(R.string.fail);
	    	}
	    }
	    mName[TestControl.name_list.length]= getResources().getString(R.string.exit);
	    mAdapter = new FactoryTestResultListAdapter(this,mName,mResult,mName.length);
		mListView.setAdapter(mAdapter);

		mListView.setOnItemClickListener(this);
	}
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub				
		int tag = (Integer) arg1.getTag();
		if(tag==(TestControl.name_list.length+1))
		{
			finish();
		}
	}

	
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		if(mWakeLock!=null)
		{
			mWakeLock.release(); 
			mWakeLock = null;
		}
		super.onDestroy();
	}
	
	 @Override
	 public boolean onKeyDown(int keyCode, KeyEvent event) {
		 		 
		 	return true;
	 }
	 
	 
	@Override
	public void onAttachedToWindow() 
	{
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	}
}
		 